#include "DataSet.h"
#include "Sample.h"

#include <iostream>

DataSet::DataSet()
{

}

DataSet::~DataSet()
{
  labels_.clear();
  samples_.clear();
}

bool DataSet::isConsistent_(const Sample& s) const
{
  if(samples_.size() > 0) {
    if(s.input().size() != samples_[0].input().size()) {
      return false;
    } else { // Input has same size now check labels
      if(labels_.size() > 0) { // There are labels for this dataset so sample should have label
        if(s.label() == -1) {
          return false;
        }
      }
    }

    return true;
  }

  return true; // It is the first sample that is added
}

void DataSet::push_back(const Sample& s)
{
  if(isConsistent_(s)){
    samples_.push_back(s);
    labels_.push_back(s.label());
  } else {
    std::cerr << "Sample not consistent with current dataset" << std::endl;
  }
}

const Sample& DataSet::sample(const unsigned int& i) const 
{
  return samples_[i];
}

const std::vector<Sample>& DataSet::samples() const 
{
  return samples_;
}

const int& DataSet::label(const unsigned int& i) const 
{
  return labels_[i];
}

const std::vector<int>& DataSet::labels() const 
{
  return labels_;
}